home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
CHASSIS_
/
FILESAVE.C
< prev
next >
Wrap
Text File
|
1992-05-14
|
3KB
|
99 lines
/************************************************************************************/
/* FileSaveProc */
/* */
/* This proc is used by menu items Save and Save As. Return code is set to 1 for */
/* all errors, except a Cancel choice out of FSPutFile. It is set to 2 for that. */
/************************************************************************************/
#include "MyHeaders.h"
int FileSaveProc (Boolean SaveAsFlag)
{
int FSRetCode = 0;
Rect dlogRect;
int rectHeight, rectWidth;
int newH, newV;
int itemHit; /* return from modal dialog */
myDlogPtr = GetNewDialog (putDlgID, NIL, (WindowPtr) -1); /* get the dialog */
dlogRect = (*myDlogPtr).portRect; /* position dlog on desktop */
rectHeight = dlogRect.bottom - dlogRect.top;
rectWidth = dlogRect.right - dlogRect.left;
newH = (screenBits.bounds.right - rectWidth) * .50; /* centered horizonally */
newH += 2; /* jive it in */
if (newH < 10) /* (not less than 10) */
newH = 10;
newV = ((screenBits.bounds.bottom - 30 /* vertical position */
- rectHeight)* (.33)) + 30; /* one-third down */
if (newV < 30) /* (not less than 30) */
newV = 30;
if ((windTbl[windSub].windPathRefNum == 0)
|| (SaveAsFlag == TRUE))
{
GetWTitle (windTbl[windSub].windPtr, &workStr255); /* name for text box */
SetPt (&workPoint, newH,newV); /* upper left corner */
SFPutFile (workPoint, NIL, &workStr255, NIL, &workReply);
if (workReply.good == FALSE) /* if cancel */
{
FSRetCode = 2; /* set cancel ret code */
goto ENDING; /* but get out anyway */
}
if (((workReply.vRefNum != windTbl[windSub].windReply.vRefNum) /* if diff. */
|| (workReply.fName != windTbl[windSub].windReply.fName))
&& (SaveAsFlag == TRUE)) /* and it is saveAs */
{
if (windTbl[windSub].windPathRefNum != 0)
{
workRC = FSClose (windTbl[windSub].windPathRefNum); /* close old */
if (workRC != noErr)
{
FSRetCode = 1;
goto ENDING;
}
windTbl[windSub].windPathRefNum = 0; /* indicate file closed */
}
}
windTbl[windSub].windReply = workReply; /* store new SF info */
workRC = Create (&windTbl[windSub].windReply.fName, /* try creating new file*/
windTbl[windSub].windReply.vRefNum, 'chAS','TEXT');
if ((workRC != noErr) /* if an error other */
&& (workRC != dupFNErr)) /* than name already is */
{
FSRetCode = 1; /* indicate error */
goto ENDING; /* and leave */
}
workRC = FSOpen (&windTbl[windSub].windReply.fName, /* open the new file */
windTbl[windSub].windReply.vRefNum,
&windTbl[windSub].windPathRefNum);
switch (workRC)
{
case (noErr):
break;
case (opWrErr): /* zero path which is */
windTbl[windSub].windPathRefNum = 0; /* from somewhere else */
FSRetCode = 1; /* set bad ret code */
goto ENDING; /* get out */
break;
default:
FSRetCode = 1; /* set bad ret code */
goto ENDING; /* get out */
break;
}
SetWTitle (windTbl[windSub].windPtr, /* name to wind title */
windTbl[windSub].windReply.fName);
}
worklong = /* transfer data to file */
WriteFromTE(windTbl[windSub].windPathRefNum,
windTbl[windSub].windTEH[0]);
windTbl[windSub].windTEChanged = FALSE; /* reset the changed flag */
ENDING:
return FSRetCode;
}